package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.MemberDao;
import com.itheima.dao.OrderDao;
import com.itheima.service.ReportService;
import com.itheima.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service(interfaceClass = ReportService.class)
public class ReportServiceImpl implements ReportService {

    @Autowired
    private MemberDao memberDao;
    @Autowired
    private OrderDao orderDao;

    @Override
    public Map<String, Object> getBusinessReport() throws Exception {

        //获得当前日期
        String today = DateUtils.parseDate2String(DateUtils.getToday());
        // 获得本周一的日期
        String thisWeekMonday = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
        // 获得本月第一天的日期
        String firstDay4ThisMonth = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());
        // 今日新增会员数
        Integer memberCount = memberDao.findMemberCountByDate(today);
        // 总会员数
        Integer memberTotalCount = memberDao.findMemberTotalCount();
        //本周新增会员数
        Integer memberCountAfterDate = memberDao.findMemberCountAfterDate(thisWeekMonday);
        //本月新增会员数
        Integer memberCountAfterDate1 = memberDao.findMemberCountAfterDate(firstDay4ThisMonth);

        //今日预约数
        Integer orderCountByDate = orderDao.findOrderCountByDate(today);
        // 本周预约数
        Integer orderCountAfterDate = orderDao.findOrderCountAfterDate(thisWeekMonday);
        // 本月预约数
        Integer orderCountAfterDate1 = orderDao.findOrderCountAfterDate(firstDay4ThisMonth);
        // 今日到诊数
        Integer visitsCountByDate = orderDao.findVisitsCountByDate(today);
        // 本周到诊数
        Integer visitsCountAfterDate = orderDao.findVisitsCountAfterDate(thisWeekMonday);
        // 本周到诊数
        Integer visitsCountAfterDate1 = orderDao.findVisitsCountAfterDate(firstDay4ThisMonth);
        //热门套餐
        List<Map> hotSetmeal = orderDao.findHotSetmeal();

        Map<String, Object> result = new HashMap<>();
        result.put("reportDate", today);
        result.put("todayNewMember", memberCount);
        result.put("totalMember", memberTotalCount);
        result.put("thisWeekNewMember", memberCountAfterDate);
        result.put("thisMonthNewMember", memberCountAfterDate1);

        result.put("todayOrderNumber", orderCountByDate);
        result.put("thisWeekOrderNumber", orderCountAfterDate);
        result.put("thisMonthOrderNumber", orderCountAfterDate1);
        result.put("todayVisitsNumber", visitsCountByDate);
        result.put("thisWeekVisitsNumber", visitsCountAfterDate);
        result.put("thisMonthVisitsNumber", visitsCountAfterDate1);
        result.put("hotSetmeal", hotSetmeal);

        return result;
    }
}
